<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>修改部门信息</title>
<%@ include file="/WEB-INF/jsp/kt/common/inc.jsp" %>
<script type="text/javascript" src="${_resources}JSON-js-master/json2.js"></script>
<script type="text/javascript" src="${_resources}js/setUserIdAndName.js"></script>
<script type="text/javascript">
$(function (){
	$("#department").validationEngine({
		autoHidePrompt:true,//自动隐藏
		showOnMouseOver:true,//当鼠标移出时触发
		promptPosition:'bottomLeft',//提示信息的位置
		inlineValidation: true,//是否即时验证，false为提交表单时验证,默认true  
		failure : function() {
		    layer.message("验证失败，请检查");
			return false;  
		},//验证失败时调用的函数
		ajaxFormValidation: true,//开始AJAX验证
		success : function() {
		//	$("#addForm").submit();
		}//验证通过时调用的函数 
		//onAjaxFormComplete: ajaxValidationCallback
	});

	var url = ""
	if("${customCode}" =="tianjin712suo"){
		url = '${_baseUrl}/departTianSevenController/getParentId'
	} else {
		url = '${_baseUrl}/departmentController/getParentId'
	}
	$.ajax({
		cache:false,
		async:false,
		type:"POST",
		url:url,
		dataType:"json",
		success: function(data){
			var obj=JSON.stringify(data);
			var innerHtml="<select style='width:100%' id='parentId' name='parentId' class='qr_select'><option value=''>请选择</option>";
			if(obj=="[]"){
				innerHtml+="";
			}else{
				innerHtml+="";
				for(var i=0;i<data.length;i++){
					if("${department.parentId}" == data[i].id){
						innerHtml+="<option selected='selected' value='"+data[i].id+"'>"+data[i].deptName+"</option>";
					}else if("${department.id}" != data[i].id){
						innerHtml+="<option value='"+data[i].id+"'>"+data[i].deptName+"</option>";
					}
				}
			}
			innerHtml+="</select>";
			$("#depart").html(innerHtml);
		}
	});
	
	$("#cancel").click(function (){
		parent.refreshTable();
		parent.closeWin();
	});
	
	$("#submit").click(function (){
		if($("#department").validationEngine('validate')){
		$("#submit").unbind("click");
		var options = {
				dataType:"json",
				success:function(json){
					if(json.code == '1'){
						layer.msg(json.message,{shift:5},function(){
							// parent.refreshTable();
							parent.window.location.reload();//
							parent.closeWin();
						});
					}
					if(json.code == '0'){
						layer.msg(json.message);
					}
				},
				error:function(json){
					layer.msg("系统错误,请联系管理员");
				}
			};
			$('#department').ajaxSubmit(options);

		}
	});
});

function selectUser(inputId){
	var choicedParentDepart = $("#parentId").val();
	
	var managerId = "";
	if(inputId=="charge"){
		managerId = $("#charge_id").val();//"${department.charge }";
	}else if(inputId == "interfacePerson"){
		managerId = $("#interfacePerson_id").val();//"${department.interfacePerson }";
	}else if(inputId == "superLeader"){
		managerId = $("#superLeader_id").val();//"${department.superLeader }";
	}else if(inputId == "manager"){
		managerId = $("#manager_id").val();//"${department.manager }";
	}
	
	layer.open({
        type: 2 //Page层类型
        ,area: ['641px', '350px']
        ,title: '选择人员'
        ,shade: 0.3 //遮罩透明度
        ,maxmin: false
        ,resize:false
        ,anim: -1 //0-6的动画形式，-1不开启
        ,content: "${_baseUrl}/departmentController/showSelectDepartUserTop?inputId="+inputId+"&managerId="+managerId+"&choicedParentDepart="+choicedParentDepart+"&random="+Math.random()
    });
}

/* 关闭弹出框 */
function closeWin(){
	layer.closeAll();
}
</script>
<style type="text/css">
select {
            width:100%;
            font-size: 13px;
            height:30px;
            float:left;
            line-height: 10px;
            padding-bottom:5px\9;
            border: solid 1px #d6d6d6;
            appearance:none;
            -moz-appearance:none;
            -webkit-appearance:none;
            background: url("${_resources}img/input_xiala.png") no-repeat  right center ;
            border-radius: 4px;
        }
        /*清除ie的默认选择框样式清除，隐藏下拉箭头*/
        select::-ms-expand { display: none !important; }

</style>
</head>
<body>
	<form name="department" id="department" action="${_baseUrl}/departmentController/edit" method="post">  
		<input type="hidden" name="id" id="id" value="${department.id }" />
	    <table class="table table-bordered ofo submenu_table" style="margin: 10px">
	      <tr>
	        <td height="50"  width="15%" align="center"><span style="color: #f00">*</span>部门名称</td>
	        <td width="35%" valign="middle">
	        	<div class="">
	        		<input type="text" name="deptName" id="deptName" value="${department.deptName }"  disabled="disabled" class="validate[required,maxSize[25]] nav_input" placeholder="请输入">
	        	</div>
	        </td>
	        <td width="15%" valign="middle" align="center"><span style="color: #f00">*</span>部门编号</td>
	        <td width="35%" valign="middle">
	        	<div class="">
	        		<input type="text" name="deptNumber" id="deptNumber" value="${department.deptNumber }" disabled="disabled"   class="validate[required,maxSize[25]] nav_input" placeholder="请输入">
	        	</div>
	        </td>
	      </tr>
	      <tr>
	        <td  width="15%" valign="middle" align="center">部门简称</td>
	        <td width="35%">
	        	<div class="">
	        		<input type="text" name="departAbbrevia" id="departAbbrevia" value="${department.departAbbrevia }" class="nav_input validate[maxSize[25]]" placeholder="请输入">
	        	</div>
	        </td>
	        <td height="50"  width="15%" align="center">上级部门</td>
			<td valign="middle"><div class="qr_input"><span id="depart" ></span></div></td>

	    	<%--<td width="35%" valign="middle">
	   			<select class="qr_select" id="parentId" name="parentId" onchange='getChoiceDepart();'>
	 				<option value="">请选择上级部门</option>
	       			<c:forEach items="${departmentList }" var="dept">
	       				<option value="${dept.id }" <c:if test="${dept.id == department.parentId }">selected="selected"</c:if> >${dept.deptName }</option>
	       			</c:forEach>
	   			</select>
	      	</td>--%>
	      </tr>
	      <tr>
	        <td height="50" width="15%" align="center"><span style="color: #f00">*</span>部门负责人</td>
	        <td width="35%" valign="middle">
	        	<div class="file_upload">
	        		<input type="text" name="chargeName" id="charge_name" value="${department.chargeName }" readonly class="validate[required] nav_input"/>
	        		<input type="hidden" name="charge" id="charge_id" value="${department.charge }"/>
	        		<a href="javascript:;"  onClick="selectUser('charge');">
	        			选择
	        		</a>
	        		
	        	</div>
	        </td>
	        <td  width="15%" valign="middle" align="center">部门接口人</td>
	        <td width="35%" valign="middle">
	        	<div class="file_upload">
	        		<input type="text" name="interfacePersonName" id="interfacePerson_name" value="${department.interfacePersonName }" readonly class="nav_input validate[maxSize[50]">
	        		<input type="hidden" name="interfacePerson" id="interfacePerson_id" value="${department.interfacePerson }"/>
	        		<a href="javascript:;" onClick="selectUser('interfacePerson');">
	        			选择
	        		</a>
	        	</div>
	        </td>
	      </tr>
	      <tr>
	        <td height="50"  width="15%" align="center">上级主管领导</td>
	        <td width="35%" valign="middle">
	        	<div class="file_upload">
	        		<input type="text" name="superLeaderName" id="superLeader_name" value="${department.superLeaderName }" readonly class="nav_input validate[maxSize[50]">
	        		<input type="hidden" name="superLeader" id="superLeader_id" value="${department.superLeader }"/>
	       			<a href="javascript:;" onClick="selectUser('superLeader');">
	       				选择
	       			</a>
	       		</div>
	       	</td>
	        <td  width="15%" valign="middle" align="center">部门管理人</td>
	        <td width="35%">
	        	<div class="file_upload">
	        		<input type="text" name="managerName" id="manager_name" value="${department.managerName }" readonly class="nav_input	 validate[maxSize[50]">
	        		<input type="hidden" name="manager" id="manager_id" value="${department.manager }"/>
	        		<a href="javascript:;" onClick="selectUser('manager');">
	        			选择
	        		</a>
	        	</div>
	        </td>
	      </tr>
	      <tr>
	        <td height="50" width="15%" align="center">部门描述</td>
	        <td colspan="3" width="35%" valign="middle" align="left">
	        	<div class="">
	        		<textarea name="comments" id="comments"  class="validate[maxSize[4000]]  nav_textarea" style="height:80px">${department.comments}</textarea>
	        	</div>
	        </td>
	      </tr>
	    </table>
		<div class="submit_group">
			<shiro:hasPermission name="departmentController:edit">
		        <a href="javascript:;" id="submit"  class="submit">保存</a>
		    </shiro:hasPermission>
			<shiro:hasPermission name="departmentController:close2">
		     <a href="javascript:;" id="cancel" class="cancel">取消</a>
		    </shiro:hasPermission>
		 </div>
	</form> 
<div id="selectDiv" style="display: none;overflow: hidden;">
	<iframe id="selectIframe" border="0" frameborder="0"></iframe>
</div>

</body>
</html>